import {mapGetters, mapMutations} from "vuex";
import {EventBus, MountedEventType} from "@/event";
import {UnionType} from "@/store/consts";
import MetaUtils from "@/utils/MetaUtils";

export const MixinContainer = {
    computed: {
        ...mapGetters({
            isEdit: 'isEdit',
            editMeta: 'editMeta',
            meta: 'containerMeta',
            funcMetas: 'containerFuncMetas',
            containerMetas: 'containerMetas'
        })
    },
    created() {
        if(this.containerMetas.length == 0) {
            this.containerMetas.push({id: MetaUtils.getMetaId(), type: 'modal'
                , union: UnionType.Edit, name: '编辑抽屉'})
            this.addToFuncList(this.containerMetas[0]);
        }
    },
    mounted() {
        EventBus.publish(MountedEventType.container, this.meta)
    },
    methods: {
        ...mapMutations(["switchPathTo", 'setContainerTabMetas', 'switchActiveMetaTo', 'addContainerMetas', 'addToFuncList']),
        isDrop(ori) {
            for(let item of this.containerMetas) {
                if(item.union == UnionType.Edit) {
                    return false;
                }
            }

            return true;
        },
        addHandle(e) {
            let metas = this.containerMetas;
            let find = metas.find(item => item.union == UnionType.List ? item : null);
            if(find == null) {
                metas.splice(0, 1);

            }
        }
    }
}
